package com.atguigu;

public class T2 {

    //二分查找
    public static int binarySeach(int[] arr,int target){
        int left = 0;
        int right = arr.length-1;

        while (left <= right){
            int mid = left + (right - left)/2;
            if(arr[mid] == target){
                return mid;
            } else if (arr[mid] > target) {
                right = mid -1;
            }else {
                left = mid +1;
            }
        }
        return -1;
    }
    public static void main(String[] args) {

        int[] arrays = new int[]{11,13,15,17,18,20,22,24};
        int target = 22;

        System.out.println(binarySeach(arrays,target));
    }
}
